package com.by.util;

import java.io.InputStream;
import java.sql.*;
import java.util.Properties;

public class DButils {
    private static String driverClass;
    private static  String url;
    private static String username;
    private static String password;

    private static Connection conn;
  //创建静态代码块 加载配置文件和驱动
    static{
      InputStream in = DButils.class.getClassLoader()
              .getResourceAsStream("JdbcConfig.properties");
      Properties prop=new Properties();
      try {
          prop.load(in);
         driverClass= prop.getProperty("driverClass");
          url=prop.getProperty("url");
          username=prop.getProperty("username");
          password=prop.getProperty("password");
          Class.forName(driverClass);
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  //获取链接方法
    public static Connection getConnection(){
        try {
            conn=DriverManager.getConnection(url,username,password);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return conn;
    }
    public static void close(Connection conn, Statement st, ResultSet resultSet){

    }



}
